package com.example.wanandroid_copy2.ui.login.viewmodel

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.example.wanandroid_copy2.R
import com.example.wanandroid_copy2.common.BaseResponse
import com.example.wanandroid_copy2.common.BaseViewModel
import com.example.wanandroid_copy2.common.network.State
import com.example.wanandroid_copy2.common.network.StateType
import com.example.wanandroid_copy2.ui.login.data.model.LoginRsp
import com.example.wanandroid_copy2.ui.login.data.model.RegisterRsp
import com.example.wanandroid_copy2.ui.login.data.repository.AccountRepository

class AccountViewModel(application: Application) : BaseViewModel<AccountRepository>(application) {


    val mLoginData = MutableLiveData<BaseResponse<LoginRsp>>()
    val mRegistData = MutableLiveData<BaseResponse<RegisterRsp>>()

    fun login(userName :String,password :String){
        mRepository.login(userName,password,mLoginData)
    }

    fun regist(userName :String,password: String,repassword: String){
        if (password != repassword) {
            loadState.postValue(State(StateType.TIP, msg = getApplication<Application>().resources.getString(R.string.password_ensure_error)))
        } else{
            mRepository.register(userName,password,repassword,mRegistData)
        }
    }

}